<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Main content
*
*/
class profile_ineo
{
	/**
	* Global IPSCLASS
	* @var	object
	*/
	var $ipsclass;
	
	/**
	* Returns a block of HTML back to the ajax handler
	* which then replaces the inline content with the HTML
	* returned.
	*
	*/
	function return_html_block( $member=array() ) 
	{
		// Set some vars:
		
		$content   = '';
		$last_x    = 5;		
		
		// Profile skin loaded?
		
		if ( ! is_object( $this->ipsclass->compiled_templates['skin_profile'] ) )
		{
			$this->ipsclass->load_template( 'skin_profile' );
		}
		
		// Member passed?
		
		if ( ! is_array( $member ) OR ! count( $member ) )
		{
			return '';
		}
		
		// Can member view Ineo?
		
		if( !$this->ipsclass->member['g_ineo_view'] )
		{
			return '';
		}
		
		// Load bbcode parser:
		
		require_once( ROOT_PATH."sources/handlers/han_parse_bbcode.php" );
        $parser                      = new parse_bbcode();
        $parser->ipsclass            = $this->ipsclass;
        $parser->allow_update_caches = 0;
        $parser->parse_html          = $member['g_dohtml'];
        $parser->bypass_badwords = intval( $this->ipsclass->member['g_bypass_badwords'] );
		$parser->parse_nl2br = 1;
		
		// Get last x articles:
		
		$this->ipsclass->DB->build_query(
											array(
													'select' => 'a.*, c.*',
													'from'   => array('ineo_articles' => 'a'),
													'add_join' => array( 0 , array( 'type' => 'left', 'from' => array('ineo_content' => 'c') , 'where' => 'c.content_article = a.article_id' )),
													'where'  => 'a.article_author = ' . $member['id'],
													'order' => 'a.article_created_date DESC',
													'limit' => array( 0, $last_x ),
												 ) 
										);
										
		$aq = $this->ipsclass->DB->exec_query();
		
		if( $this->ipsclass->DB->get_num_rows($aq) < 1 )
		{
			return 'No articles.';
		}
		
		while( $row = $this->ipsclass->DB->fetch_row( $aq ) )
		{
			$row['_post_date']  = $this->ipsclass->get_date( $row['article_created_date'], 'SHORT' );
			$row['_date_array'] = $this->ipsclass->date_getgmdate( $row['article_created_date'] );
			$row['post'] = $parser->pre_display_parse( $row['content_content'] );
			
			$row['post'] = str_replace( "<#IMG_DIR#>", $this->ipsclass->skin['_imagedir'], $row['post'] );
			$row['post'] = str_replace( "<#EMO_DIR#>", $this->ipsclass->skin['_emodir']  , $row['post'] );
			
			$content .= $this->ipsclass->compiled_templates['skin_profile']->personal_portal_single_column( $row, 'Read Article', $this->ipsclass->base_url.'autocom=ineo&showarticle='.$row['article_id'] );
		}
		
		//-----------------------------------------
		// Return content..
		//-----------------------------------------
		
		return $content;
	}
	
}


?>